package com.example.replacebooks.controller;

import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.User;
import com.example.replacebooks.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private UserService userService;

//   登录
    @PostMapping
    public Result login(@RequestBody User user){
        User loginUser = userService.login(user);
        return Result.success(loginUser);
    }
//    注册
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        userService.register(user);
        return Result.success();
    }
}
